﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GdCmts
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private bool ScanStatus = false;
        private readonly string TunnelUrl = "http://172.16.5.198/cmts/copyOfMain.in?module=popedom&method=getUnsentCurrentWarnList"; //cmts信息采集地址

        private void Form1_Load(object sender, EventArgs e)
        {
            
        }

        private void ScanWarn()
        {
            //string datastr = DataFunc.Instance.ReadWebUrl(TunnelUrl);
            string datastr = "{\"items\":[{\"beginTime\":\"2013-06-01 16:07:59.0\",\"cmtsName\":\"GZ-GZL-CMTS-1.M.UBR10K\",\"upChannelName\":\"C7/0/1/U1\",\"warnMsg\":\"通道SNR:13,宽带利用率:52%,\"} ]}";
            richTextBox1.Text = datastr;
            if (datastr.Contains("[错误]"))
            {
                return;
            }
            List<TunnelInfo> TIS = DataFunc.Instance.FormatData(datastr);

        }

        private void WriteLog(string log)
        {
            if (richTextBox1.TextLength > 99999) richTextBox1.Text = "";
            richTextBox1.Text = DateTime.Now.ToString() + " " + log + "\r\n" + richTextBox1.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!ScanStatus)
            {
                ScanStatus = true;
                button1.Text = "停止扫描";
                label1.Text = "扫描开始于[" + DateTime.Now.ToString() + "]。";
                timer1.Interval = 2000;
                timer1.Start();
            }
            else
            {
                timer1.Stop();
                ScanStatus = false;
                button1.Text = "启动扫描";
                label1.Text = "扫描已停止。";
                label2.Text = "";
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            label2.Text = "下次扫描："+ DateTime.Now.AddSeconds(timer1.Interval / 1000).ToString();
            WriteLog("开始进行扫描。");
            WriteLog("扫描已经结束。");
        }
    }
}
